#!/bin/bash

err() {
    echo $1
    exit $2
}

parse_file() {
    echo -n "[$(date +"%F %T")] " >> $logfile
    if python3 lagou_parse.py $1 2>> $logfile ; then
        echo "$1 解析成功!" >> $logfile
    fi
}

parse_dir() {
    for f in $(find $1 -name "*.html") ; do
        parse_file $f
    done
}

test -z $1 && err "请指定解析文件或目录!" 1

if test -z $KYO_LAGOU_LOG ; then
    logfile=parse.log
else
    logfile=$KYO_LAGOU_LOG
fi

test -f $1 && parse_file $1 || parse_dir $1
